<template>
	<div class="ai-speak-wrapper">
		<template v-if="videoType === 'real-time-fitting' || videoType === 'no-video' || videoType === 'video-switching'">
			<NormalSpeakInput
				v-if="!isNumber(prop)"
				:rules="rules"
				@onAddVariable="onAddVariable"
				@showVideoTable="showVideoTable"
				:variableIcon="variableIcon"
				:placeholder="placeholder"
				:textArea="textArea"
				:label="label"
				:showDetail="showDetail"
				:required="required"
				:value="value"
				:taskId="taskId"
				@input="input"
				:prop="prop"
				:minlength="minlength"
				:maxlength="textArea ? 500 : maxlength"
				:insertStr="insertStr"
			/>
		</template>
		<!-- 预录制 原生视频 -->
		<template v-if="videoType === 'pre-recorded-video' && audioType === 'video-native'">
			<PrerecordNativeVideoInput
				v-if="!isNumber(prop)"
				:rules="rules"
				@onAddVariable="onAddVariable"
				@showVideoTable="showVideoTable"
				:validateStatus="validateStatus"
				:placeholder="placeholder"
				:label="label"
				:showDetail="showDetail"
				:textArea="textArea"
				:video="video"
				:value="video"
				:required="required"
				:taskId="taskId"
				@input="input"
				@clearVideo="clearVideo"
				:prop="`${prop}Video`"
				:minlength="minlength"
				:maxlength="textArea ? 500 : maxlength"
			/>
		</template>
		<!-- 预录制 TTS -->
		<template v-if="videoType === 'pre-recorded-video' && audioType === 'tts'">
			<PrerecordTtsInput
				v-if="!isNumber(prop)"
				:rules="rules"
				@onAddVariable="onAddVariable"
				@showVideoTable="showVideoTable"
				:validateStatus="validateStatus"
				:variableIcon="variableIcon"
				:placeholder="placeholder"
				:textArea="textArea"
				:label="label"
				:showDetail="showDetail"
				:video="video"
				:required="required"
				:value="value"
				:taskId="taskId"
				@input="input"
				@clearVideo="clearVideo"
				:prop="prop"
				:minlength="minlength"
				:maxlength="textArea ? 500 : maxlength"
			/>
		</template>
		<!-- 数值类型 -->

		<SpeakWaitTime
			:rules="rules"
			:prop="prop"
			:label="label"
			:showDetail="showDetail"
			:placeholder="placeholder"
			:minlength="minlength"
			:maxlength="textArea ? 500 : maxlength"
			:required="required"
			@input="input"
			:value="value"
			:maxTips="maxTips"
			v-if="isNumber(prop)"
		/>
	</div>
</template>

<script>
import AIWorkflow from '@/modules/workFlow';
import PrerecordNativeVideoInput from './PrerecordNativeVideoInput.vue';
import NormalSpeakInput from './NormalSpeakInput.vue';
import PrerecordTtsInput from './PrerecordTtsInput .vue';
import SpeakWaitTime from './SpeakWaitTime.vue';

export default {
	components: {
		PrerecordNativeVideoInput,
		PrerecordTtsInput,
		NormalSpeakInput,
		SpeakWaitTime
	},
	props: {
		variableIcon: {
			type: Boolean,
			default: () => true
		},
		label: {
			type: String,
			default: () => 'AI说'
		},
		value: {
			type: String,
			default: () => ''
		},
		video: {
			type: [Object || null],
			default: () => {}
		},
		required: {
			type: Boolean,
			default: () => false
		},
		prop: {
			type: String,
			default: () => ''
		},
		placeholder: {
			type: String,
			default: () => '请输入AI客服播报的话术'
		},
		taskId: {
			type: String,
			default: () => '',
			required: false
		},
		showDetail: {
			type: Boolean,
			default: () => false
		},
		videoIcon: {
			type: String,
			default: () => ''
		},
		minlength: {
			type: Number,
			default: () => 1
		},
		maxlength: {
			type: Number,
			default: () => 140
		},
		validateStatus: {
			type: Boolean,
			default: () => true
		},
		textArea: {
			type: Boolean,
			default: () => false
		},
		rules: {
			type: Object,
			default: () => {}
		},
		maxTips: {
			type: Boolean,
			default: () => false
		}
	},

	data() {
		return {
			tableVideoType: 'speak',
			videoType: '',
			audioType: ''
		};
	},

	watch: {},

	methods: {
		onAddVariable(data) {
			this.$emit('onAddVariable', data);
		},

		showVideoTable(data) {
			this.$emit('showVideoTable', data);
		},
		clearVideo(prop) {
			console.log('clearVideo');
			this.$emit('clearVideo', prop, null);
		},
		input(prop, e) {
			console.log(prop, e);
			this.$emit('input', prop, e);
		}
	},

	mounted() {
		const { videoType = null, audioType = null } = AIWorkflow.getRobotProperty();
		this.videoType = videoType;
		this.audioType = audioType;
		console.log('aiSpeak validateStatus @@@111222', this.validateStatus);
	},
	computed: {
		hasSelectVideoIcon() {
			return AIWorkflow.hasSelectVideoIcon(this.taskId);
		},
		isNumber() {
			return prop => {
				return AIWorkflow.getNumberTypeProperty(prop);
			};
		},
		isMaxTips() {
			return prop => {
				return ['noAnswerTimesMax', 'otherTimesMax', 'wordsOverTime', 'otherWaitTime', 'noAnswerOverTime', 'wordsTimesMax', 'resultFailedTimesMax'].indexOf(prop) > -1;
			};
		}
	}
};
</script>

<style></style>
